﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace PingPong
{
    public class Draw
    {
        public void DrawBall(Ball ball)
        {
            Console.ForegroundColor = ConsoleColor.Green ;
            Console.SetCursorPosition(ball.BallPosition[0], ball.BallPosition[1]);
            Console.Write(ball.BallChar);
        }

        public void DrawPad(Pad pad)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            for (int i = 0; i < pad.Size; i++)
            {
                int x = pad.Position[0];
                int y = pad.Position[1]+i;
                Console.SetCursorPosition(x, y);
                Console.Write('|');
            }
        }
        // Nikola - вече имаме метод за точки, тоя е малко ненужен
        /*
        public void PrintScore(Player player1, Player player2, PlayGround playground)
        {
            throw new System.NotImplementedException();
        }
        */
        public void DrawPlayGround(PlayGround playground)
        {
            // top
            Console.ForegroundColor = ConsoleColor.Cyan;
            string horizontal = new String('\u2588', playground.Width);
            Console.SetCursorPosition(0, 1);
            Console.Write(horizontal);
            //// down
            Console.SetCursorPosition(0, Console.BufferHeight-1);
            Console.Write(horizontal);
        }

        public void DrawObstacle(List<Obstacle> obstacles)
        {
            foreach (var obstacle in obstacles)
            {
                Console.SetCursorPosition(obstacle.PositionX, obstacle.PositionY);
                
                Console.ForegroundColor = obstacle.Color;
                Console.Write(obstacle.CurrentSymbol);
            }
        }

        public static void DrawStartScreen(PlayGround playground)
        {
            var pictureArray = new char[30, 97];
            string fileName = @"..//..//asciiart.txt";
            StreamReader readFileEnd = new StreamReader(fileName);
            PingPong.Theme();
            using (readFileEnd)
            {
                string readLineOfFile = readFileEnd.ReadLine();
                int indexRow = 0;
                while (readLineOfFile != null)
                {
                    for (int i = 0; i < readLineOfFile.Length; i++)
                    {
                        pictureArray[indexRow, i] = readLineOfFile[i];
                    }
                    indexRow++;
                    readLineOfFile = readFileEnd.ReadLine();
                }
            }

            //StringBuilder strBuilder = new StringBuilder();

            for (int t = 0; t < 30; t++)
            {
                for (int j = 0; j < 97; j++)
                {
                    Console.Write(pictureArray[t, j]);
                }
                Console.WriteLine();
            }
            Console.WriteLine();
            Console.SetCursorPosition(playground.Width / 2 - 4, playground.Height - 5);
        }

        public static string AskForPlayerName()
        {
            //Console.WriteLine("Please enter your name:");
            return Console.ReadLine();
        }
    }
}
